package com.ln.lnzw.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.ln.lnzw.R;
import com.ln.lnzw.base.BaseActivity;
import com.ln.lnzw.utils.CacheActivity;
import com.ln.lnzw.view.ClearableEditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wuwei on 2018/4/13.
 */

public class ResetPasswordActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.cet_mima_one)
    ClearableEditText cetMimaOne;
    @BindView(R.id.cet_mima_two)
    ClearableEditText cetMimaTwo;
    @BindView(R.id.rl_tijiao)
    RelativeLayout rlTijiao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reset_password);
        ButterKnife.bind(this);
        CacheActivity.addActivity(ResetPasswordActivity.this);
        setView();
    }

    private void setView() {
        cetMimaOne.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                editTextIsYes();
                editTextIsNo();
            }
        });
        cetMimaTwo.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                editTextIsYes();
                editTextIsNo();
            }
        });

    }
    private void editTextIsNo() {
        if (TextUtils.isEmpty(cetMimaOne.getText())||TextUtils.isEmpty(cetMimaTwo.getText())){
            rlTijiao.setBackground(getResources().getDrawable(R.drawable.button_bg_no));
        }
    }

    private void editTextIsYes() {
        if (!TextUtils.isEmpty(cetMimaOne.getText())&&!TextUtils.isEmpty(cetMimaTwo.getText())){
            rlTijiao.setBackground(getResources().getDrawable(R.drawable.button_bg_yes));
        }
    }
    @OnClick({R.id.iv_back, R.id.rl_tijiao})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.rl_tijiao:
                if (TextUtils.isEmpty(cetMimaOne.getText())||TextUtils.isEmpty(cetMimaTwo.getText())){
                    return;
                }
                CacheActivity.finishActivity();
                break;
        }
    }
}
